<?php


namespace dsp\mediator;


use dsp\mediator\conceptual\Component1;
use dsp\mediator\conceptual\Component2;
use dsp\mediator\conceptual\ConcreteMediator;
use dsp\mediator\RealWorld\Logger;
use dsp\mediator\RealWorld\OnboardingNotification;
use dsp\mediator\RealWorld\UserRepository;
use kernel\BaseMain;

class Main extends BaseMain
{

    public function execute($choice = 'all')
    {

    }

    public function excReal()
    {
        $repository = new UserRepository();
        events()->attach($repository, 'facebook:update');

        $logger = new Logger(__DIR__ . "/log.txt");
        events()->attach($logger, "*");

        $onboarding = new OnboardingNotification("1@example.com");
        events()->attach($onboarding, "users:created");

        $repository->initialize(__DIR__ . "users.csv");

        $user = $repository->createUser([
            "name" => "John Smith",
            "email" => "john99@example.com",
        ]);

        $user->delete();
        echo PHP_EOL;
        echo json_encode(events()->observers);
    }

    public function excCpt()
    {
        $c1 = new Component1();
        $c2 = new Component2();
        $mediator = new ConcreteMediator($c1, $c2);

        echo "Client triggers operation A." . PHP_EOL;
        $c1->doA();

        echo PHP_EOL;
        echo "Client triggers operation D." . PHP_EOL;
        $c2->doD();
    }
}